package com.ruoyi.system.controller;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.system.dto.req.AuthenticationReqDto;
import com.ruoyi.system.dto.req.DeviceReqDto;
import com.ruoyi.system.dto.req.InstitutionReqDto;
import com.ruoyi.system.dto.req.PersonReqDto;
import com.ruoyi.system.dto.resq.DeviceRespDto;
import com.ruoyi.system.dto.resq.PersonRespDto;
import com.ruoyi.system.dto.resq.TInstitutionRespDto;
import com.ruoyi.system.service.TDeviceService;
import com.ruoyi.system.service.TInstitutionService;
import com.ruoyi.system.service.TPersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 数据管理Controller
 *
 * @author SUNLIANG
 */
@RestController
@RequestMapping("/data")
public class DataManagementController extends BaseController {

    @Autowired
    private TDeviceService tDeviceService;

    @Autowired
    private TInstitutionService tInstitutionService;

    @Autowired
    private TPersonService tPersonService;

    /**
     * 获取机构信息列表
     */
    @PostMapping("/institutionList")
    public TableDataInfo institutionList(@RequestBody InstitutionReqDto institutionReqDto) {
        startPage();
        List<TInstitutionRespDto> list = tInstitutionService.selectInstitutionList(institutionReqDto);
        return getDataTable(list);
    }

    /**
     * 根据机构编号获取机构详细信息
     */
    @GetMapping(value = "/institution/{institutionId}")
    public AjaxResult getInstitutionInfo(@PathVariable String institutionId) {

        return AjaxResult.success(tInstitutionService.selectOneByInstitutionId(institutionId));
    }

    /**
     * 机构认证审核  1-通过 2-不通过
     */
    @PutMapping(value = "/institution/editAuthentication")
    public AjaxResult editAuthentication(@RequestBody AuthenticationReqDto authenticationReqDto) {

        return tInstitutionService.editAuthentication(authenticationReqDto);
    }

    /**
     * 根据机构编号获取机构审核记录
     */
    @GetMapping(value = "/institution/getInstitutionAuditList/{institutionId}")
    public AjaxResult getInstitutionAuditList(@PathVariable String institutionId) {

        return AjaxResult.success(tInstitutionService.getInstitutionAuditList(institutionId));
    }


    /**
     * 根据机构编号获取机构持有设备信息
     */
    @GetMapping(value = "/getDeviceListByInstitutionId/{institutionId}")
    public TableDataInfo getDeviceListByInstitutionId(@PathVariable("institutionId") String institutionId) {
        startPage();
        List<DeviceRespDto> list = tInstitutionService.getDeviceListByInstitutionId(institutionId);
        return getDataTable(list);
    }

//======================================================================================================================
    /**
     * 获取用户信息列表
     */
    @PostMapping("/personList")
    public TableDataInfo personList(@RequestBody PersonReqDto personReqDto) {
        startPage();
        List<PersonRespDto> list = tPersonService.selectPersonList(personReqDto);
        return getDataTable(list);
    }

    /**
     * 根据用户编号获取用户详细信息
     */
    @GetMapping(value = "/person/{personId}")
    public AjaxResult getPersonInfo(@PathVariable String personId) {

        return AjaxResult.success(tPersonService.selectOneByPersonId(personId));
    }

    /**
     * 根据用户编号获取用户持有设备信息
     */
    @GetMapping(value = "/getDeviceListByPersonId/{personId}")
    public TableDataInfo getDeviceListByPersonId(@PathVariable("personId") String personId) {
        startPage();
        List<DeviceRespDto> list = tPersonService.getDeviceListByPersonId(personId);
        return getDataTable(list);
    }

//======================================================================================================================
    /**
     * 获取设备信息列表
     */
    @PostMapping("/deviceList")
    public TableDataInfo deviceList(@RequestBody DeviceReqDto deviceReqDto) {
        startPage();
        List<DeviceRespDto> list = tDeviceService.selectDeviceList(deviceReqDto);
        return getDataTable(list);
    }

    /**
     * 根据设备编号获取设备详细信息
     */
    @GetMapping(value = "/device/{deviceId}")
    public AjaxResult getDeviceInfo(@PathVariable String deviceId) {

        return AjaxResult.success(tDeviceService.selectOneByDeviceId(deviceId));
    }



}
